﻿using System;
using System.ComponentModel;

namespace MECopter.Quadrocopter
{
    public class PIDParameters : INotifyPropertyChanged
    {
        #region Fields
        //Yaw
        public float YawPGain
        {
            get { return _yawPGain; }
            set
            {
                if (value != _yawPGain)
                {
                    _yawPGain = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("YawPGain"));
                }
            }
        }
        public float YawIGain
        {
            get { return _yawIGain; }
            set
            {
                if (value != _yawIGain)
                {
                    _yawIGain = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("YawIGain"));
                }
            }
        }
        public float YawDGain
        {
            get { return _yawDGain; }
            set
            {
                if (value != _yawDGain)
                {
                    _yawDGain = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("YawDGain"));
                }
            }
        }


        //Pitch
        public float PitchPGain
        {
            get { return _pitchPGain; }
            set
            {
                if (value != _pitchPGain)
                {
                    _pitchPGain = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("PitchPGain"));
                }
            }
        }

        public float PitchIGain
        {
            get { return _pitchIGain; }
            set
            {
                if (value != _pitchIGain)
                {
                    _pitchIGain = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("PitchIGain"));
                }
            }
        }

        public float PitchDGain
        {
            get { return _pitchDGain; }
            set
            {
                if (value != _pitchDGain)
                {
                    _pitchDGain = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("PitchDGain"));
                }
            }
        }


        //Roll
        public float RollPGain
        {
            get { return _rollPGain; }
            set
            {
                if (value != _rollPGain)
                {
                    _rollPGain = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("RollPGain"));
                }
            }
        }

        public float RollIGain
        {
            get { return _rollIGain; }
            set
            {
                if (value != _rollIGain)
                {
                    _rollIGain = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("RollIGain"));
                }
            }
        }

        public float RollDGain
        {
            get { return _rollDGain; }
            set
            {
                if (value != _rollDGain)
                {
                    _rollDGain = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("RollDGain"));
                }
            }
        }


        private float _yawPGain;
        private float _yawIGain;
        private float _yawDGain;

        private float _pitchPGain;
        private float _pitchIGain;
        private float _pitchDGain;

        private float _rollPGain;
        private float _rollIGain;
        private float _rollDGain;
        #endregion

        #region Constructor
        public PIDParameters()
        {
        }
        public PIDParameters(float[] yawGains, float[] pitchGains, float[] rollGains)
        {
            SetParameters(yawGains, pitchGains, rollGains);
        }     
        #endregion

        public void SetParameters(float[] yawGains, float[] pitchGains, float[] rollGains)
        {
            this.YawPGain = yawGains[0];
            this.YawIGain = yawGains[1];
            this.YawDGain = yawGains[2];

            this.PitchPGain = pitchGains[0];
            this.PitchIGain = pitchGains[1];
            this.PitchDGain = pitchGains[2];

            this.RollPGain = rollGains[0];
            this.RollIGain = rollGains[1];
            this.RollDGain = rollGains[2];
        }     

        #region Eventhandler
        protected void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
                handler(this, e);
        }
        public event PropertyChangedEventHandler PropertyChanged;
        #endregion

    }
}
